<?php
require_once 'common.php';
require_once 'Student.php';
require_once 'ResultData.php';


if (isGet()) {
    echo "不得以GET访问";
    exit;
}

$id = trim($_REQUEST['id']);


$result = new ResultData();
if ($id == "") {
    $result->code = 404;
    $result->msg = "id不能为空";
    exit(json_encode($result));
}

$student = new Student();
$result->data = $student;
$json_string = file_get_contents('data.json');
// 用参数true把JSON字符串强制转成PHP数组
$data = json_decode($json_string);
$id = intval($id);

foreach ($data as $key => $value) {
    if ($value->id == $id) {
        $student->name = $value->name;
        $student->sex = $value->sex;
        $student->age = $value->age;
        $student->edu = $value->edu;
        $student->city = $value->city;
        $student->no = $value->no;
    }
}

exit(json_encode($result));
